package lulin.w09.controller;

import lulin.w09.entity.School;
import lulin.w09.service.SchoolServiceInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/schools")
public class SchoolController {

    @Autowired
    private SchoolServiceInterface schoolService;

    @PostMapping
    public Long addSchool(@RequestBody School school) {
        return schoolService.addSchool(school);
    }

    @DeleteMapping("/{id}")
    public int deleteSchool(@PathVariable Long id) {
        return schoolService.deleteSchool(id);
    }

    @PutMapping
    public int updateSchool(@RequestBody School school) {
        return schoolService.updateSchool(school);
    }

    @GetMapping("/{id}")
    public School getSchool(@PathVariable Long id) {
        return schoolService.getSchool(id);
    }

    @GetMapping
    public List<School> getAllSchools() {
        return schoolService.getAllSchools();
    }
}    